package com.rocketmq.base.example.delay;

import com.rocketmq.base.example.Const;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
 import org.apache.rocketmq.common.message.Message;

import java.time.LocalDateTime;
import java.util.Date;

public class ScheduledMessageProducer {

     public static void main(String[] args) throws Exception {
         // Instantiate a producer to send scheduled messages
         DefaultMQProducer producer = new DefaultMQProducer("ExampleProducerGroup");
         producer.setNamesrvAddr(Const.nameServer);
         // Launch producer
         producer.start();
         int totalMessagesToSend = 1;
         for (int i = 0; i < totalMessagesToSend; i++) {
             Message message = new Message("DELAYTOPIC", ("Hello scheduled message " + i).getBytes());
             // This message will be delivered to consumer 10 seconds later.
             //1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
                message.setDelayTimeLevel(3);
             // Send the message
             System.out.println("当前时间"+ LocalDateTime.now());
             producer.send(message);
         }

         // Shutdown producer after use.
         producer.shutdown();
     }

 }
